const fs = require('fs')
const path = require('path')

const Config = require('../../webpack.base.config')

function createEnrty () {
  console.log('a')

  const pathFile = path.resolve(__dirname, '../../src', Config.path)

  const files = fs.readdirSync(pathFile)

  let pageEntry = {} // 入口文件集合
  let plugins = [] // html 模板
  files.map(file => {
    let suffix = path.extname(file)
    let fileName = path.basename(file, suffix)
    console.log(fileName)

    // 入口文件路径
    let pageIndex = path.resolve(pathFile, file)

    let plugin = {
      template: path.resolve(__dirname, '../../', Config.template),
      filename: fileName + '.html',
      title: Config.pages[fileName] ? Config.pages[fileName].title : '',
      inject: 'body'
    }

    plugins.push(plugin)

    pageEntry[fileName] = pageIndex
  })

  return { entry: pageEntry, plugins }
}

module.exports = {
  createEnrty
}
